Do not connect to a non-existing signal
authorEmmanuele Bassi <ebassi@gnome.org>
Tue, 26 Mar 2019 17:13:18 +0000 (17:13 +0000)
committerEmmanuele Bassi <ebassi@gnome.org>
Tue, 26 Mar 2019 17:37:49 +0000 (17:37 +0000)
The GtkWidget::parent-set signal was removed in ff6cd8f7.

Instead of removing GtkLayoutChild instances associated to a widget
using notifications when the widget's parent changes, we can have
gtk_widget_unparent() call a method on GtkLayoutManager to remove any
eventual GtkLayoutChild instances associated to the widget.

gtk/gtklayoutmanager.c
gtk/gtklayoutmanagerprivate.h
gtk/gtkwidget.c

index 5047a58b2077f89f305c36a77743ece0562d5f13..3f0515826294e0ff0963e1031d5a08fbab49a641 100644 (file)
@@ -283,12 +283,19 @@ gtk_layout_manager_layout_changed (GtkLayoutManager *manager)
     gtk_widget_queue_resize (priv->widget);
 }
 
-static void
-remove_layout_child (GtkWidget        *widget,
-                     GtkWidget        *old_parent,
-                     GtkLayoutManager *self)
+/*< private >
+ * gtk_layout_manager_remove_layout_child:
+ * @manager: a #GtkLayoutManager
+ * @widget: a #GtkWidget
+ *
+ * Removes the #GtkLayoutChild associated with @widget from the
+ * given #GtkLayoutManager, if any is set.
+ */
+void
+gtk_layout_manager_remove_layout_child (GtkLayoutManager *manager,
+                                        GtkWidget        *widget)
 {
-  GtkLayoutManagerPrivate *priv = gtk_layout_manager_get_instance_private (self);
+  GtkLayoutManagerPrivate *priv = gtk_layout_manager_get_instance_private (manager);
 
   if (priv->layout_children != NULL)
     {
@@ -296,8 +303,6 @@ remove_layout_child (GtkWidget        *widget,
       if (g_hash_table_size (priv->layout_children) == 0)
         g_clear_pointer (&priv->layout_children, g_hash_table_unref);
     }
-
-  g_signal_handlers_disconnect_by_func (widget, remove_layout_child, self);
 }
 
 /**
@@ -372,7 +377,6 @@ gtk_layout_manager_get_layout_child (GtkLayoutManager *manager,
   g_assert (g_type_is_a (G_OBJECT_TYPE (res), GTK_TYPE_LAYOUT_CHILD));
 
   g_hash_table_insert (priv->layout_children, child, res);
-  g_signal_connect (child, "parent-set", G_CALLBACK (remove_layout_child), manager);
 
   return res;
 }
index d02ed56a6fc660e86becf77ff12085fb582edb95..14eb30e161d48a6e91b3346f36e75ca8ea786dec 100644 (file)
@@ -7,4 +7,7 @@ G_BEGIN_DECLS
 void gtk_layout_manager_set_widget (GtkLayoutManager *manager,
                                     GtkWidget        *widget);
 
+void gtk_layout_manager_remove_layout_child (GtkLayoutManager *manager,
+                                             GtkWidget        *widget);
+
 G_END_DECLS
index 9d0dccc665caf71948b8ab5974a8247843c80d0a..85c1bd06e5ee0b5431810c6a4f2ce2c1deb20e49 100644 (file)
@@ -3209,6 +3209,9 @@ gtk_widget_unparent (GtkWidget *widget)
   if (old_parent->priv->children_observer)
     gtk_list_list_model_item_removed (old_parent->priv->children_observer, old_prev_sibling);
 
+  if (old_parent->priv->layout_manager)
+    gtk_layout_manager_remove_layout_child (old_parent->priv->layout_manager, widget);
+
   /* Now that the parent pointer is nullified and the unroot vfunc already
    * called, go ahead and unset the parent window, if we are unparenting
    * an embedded GtkWindow the window will become toplevel again and root